package cn.java71.servlet;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import java.util.Date;

/**
    监听session的创建
 * @author oldliu
 * @since 1.0
 */

@WebListener
public class MySessionListener implements HttpSessionListener {
    @Override
    public void sessionCreated(HttpSessionEvent httpSessionEvent) {
        System.out.println(httpSessionEvent.getSession().getId()+" 创建于"+new Date());
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
        System.out.println(httpSessionEvent.getSession().getId()+" 销毁于"+new Date());
        Object o=httpSessionEvent.getSession().getAttribute("LOGIN_USER");
        System.out.println("用户："+o+"退出了。。。");
    }
}
